home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / ae / code / ax3.00 / string_in_file.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-03  |  1.7 KB  |  60 lines

  1. #include "bbs.h"
  2.  
  3. /* string_in_file.c */
  4.  
  5. /* a given filename to a list of strings we want to check for. *
  6.  * If the string exists in the list, return TRUE, otherwise    *
  7.  * return FALSE (even if the file can't be opened).            *
  8.  */
  9.  
  10. /* fname is name of file */
  11. /* str = ptr to filename of file to upload */
  12. /* use flag for wild */
  13.  
  14. #define USE_WILD_ASTER 0x01
  15. #define USE_WILD_ALL   0x02
  16. #define USE_WILD_AMY   0x04   /* use #? */
  17.  
  18. int String_In_File(char *fname, char *str, int flag)
  19. {
  20.  FILE *fp;
  21.  char buff[255];
  22.  register char *s, *p, *tmpstr;
  23.  
  24.  if(!(fp = fopen(fname,"r"))) {    /* can't find our file */
  25.      return(FALSE);    /* can't open file so nope string doesn't exist */
  26.  }
  27.  while(fgets(&buff[0],255,fp)!=0) {
  28.      buff[strlen(buff)-1] = '\0';                     /* remove newline (dunno why) */
  29.      s = &buff[0];
  30.  
  31.      /* skip beginning spaces */
  32.      while(*s == ' ')        s++;
  33.      p = s;
  34.  
  35.      if(flag) {    /* use '*' as wild card */
  36.          while(*p && *p!= '*')     p++;
  37.          if(*p == '*')  { /* found a wild card, everything after this can not be sent up */
  38.              p++;                        /* move past aster */
  39.              tmpstr = str+strlen(str)-1;   /* goto last char in string */
  40.              tmpstr -= strlen(p) -1;       /* backup p chars - 1 */
  41.              if(stricmp(tmpstr,p) == 0) {
  42.                  fclose(fp);
  43.                  return(TRUE);     /* found text in list */
  44.              }
  45.          }
  46.  
  47.      }
  48.  
  49. //     sprintf(WORKB,"looking for: [%s] in [%s]\n",str,s);
  50. //     ErrorLog(WORKB);
  51.      if(strnicmp(s,str,strlen(str)) == 0) {
  52.            fclose(fp);
  53.            return(TRUE);     /* found text in list */
  54.      }
  55.  
  56.  }
  57.  fclose(fp);
  58.  return(FALSE);                 /* didn't find text in list */
  59. }
  60.